﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CNDM.UserControls.List
{
    public partial class ucListHome : System.Web.UI.UserControl
    {
        private int _catId = 0;
        private int _top = 0;
        private string _catname;

        public string CatName
        {
            get { return _catname; }
            set { _catname = value; }
        }

        public int Top
        {
            get { return _top; }
            set { _top = value; }
        }
        public int Cat_ID
        {
            get { return _catId; }
            set { _catId = value; }
        }

        public void BindData()
        {
            DataTable dt = new DataTable();
            dt = BO.News.NewsData.Get_NoiBatChuyenMuc(_catId, _top);
            if (dt == null || dt.Rows.Count == 0)
            {
                dt = BO.News.NewsData.Get_DanhSachTin("0", _catId.ToString(), 1, _top);
            }
            ltrCatName.Text = _catname;
            repCat.DataSource = dt;
            repCat.DataBind();
        }

        protected void repCat_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Image imgNews = (Image)e.Item.FindControl("imgNews");
                if (DataBinder.Eval(e.Item.DataItem, "News_Image").ToString().Trim() == "")
                {
                    imgNews.Visible = false;
                }
                else
                {
                    imgNews.Visible = true;
                    imgNews.ImageUrl = DataBinder.Eval(e.Item.DataItem, "Image_Url").ToString();
                }          

                
            }
        }
    }
}